﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Collider))]
public class AlertBehaviour : MonoBehaviour
{
    public List<RoleController> listTarget;


    private void OnTriggerEnter(Collider other)
    {
        RoleController role = other.GetComponent<RoleController>(); 

        if(role != null && listTarget.IndexOf(role) == -1)
            listTarget.Add(role);
    }

    private void OnTriggerExit(Collider other)
    {
        RoleController role = other.GetComponent<RoleController>(); 
        if(role !=null && listTarget.IndexOf(role) > -1)   
            listTarget.Remove(role);    
    }
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Clean();
    }

    public void Clean()
    {
        for (int i = 0; i < listTarget.Count; i++)
        {
            if (listTarget[i].Hp <= 0)
            {
                listTarget.Remove(listTarget[i]);
                i--;    
            }
                
        }
    }
}
